﻿Public Class clsJp
    Public Function insert(oper_type As String, material_code As String, oper_num As String, oper As String, mes_sync_status As String, b_pgd_mes_sys_id As String) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "insert into sf.b_jp(oper_type,material_code,oper_num,operator,b_pgd_mes_sys_id,update_time,mes_sync_status) "
            szSql &= " values (?,?,?,?,?,(SELECT CURRENT_TIMESTAMP(6)),?)"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, oper_type, material_code, oper_num, oper, b_pgd_mes_sys_id, mes_sync_status)
            szSql = "UPDATE sf.b_pgd_mes_details  "
            szSql &= " SET finish_count_bg_me = finish_count_bg_me + ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " WHERE b_pgd_mes_sys_id = ? and material_code = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, oper_num, b_pgd_mes_sys_id, material_code)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

    Public Function del(sysId As String) As Integer
        Dim szSql As String = String.Empty
        szSql &= "delete from sf.b_jp where sys_id = ?"
        Return DBacs.ExecuteUpdateSql(szSql, -1, sysId)
    End Function

    Public Function getList(startTime As String, endTime As String, material_code As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select a.*,b.name,b.type,b.spec,b.model from sf.b_jp a "
        szSql &= " left join sf.t_mst_jp b on a.material_code = b.material_code "
        szSql &= " where 1=1 "
        If material_code <> "" Then
            szSql &= " and a.material_code >= '" + material_code + "'"
        End If
        If startTime <> "" Then
            szSql &= " and a.update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and a.update_time <= '" + endTime + "'"
        End If
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

End Class
